(function(){
	var AjaxCrud = QualityCheck.AjaxCRUD;
	var serverUrl = QualityCheck.GPUD.ServiceConfig;
	$(function(){
		initPages();
		window.onresize = function () {
			initPages();
		};
		getTeacherCode();
		pageBtns();
	});
	function getTeacherCode(){
		var userKey = $("#user-name",parent.document).attr("key");
		var cellphone = $("#user-name",parent.document).attr("code");
		var data = {
				cmd:"getTeacher",
				model:"teacher",
				userKey:userKey,
				data:{
					cellphone:cellphone
				},
				remark:"",
		};
		AjaxCrud.get(serverUrl.ServerLoginUrl,data,function(cres){
			if(cres.result == 1 && cres.data != undefined){
				var teachercode = cres.data.teachercode;
				var classcode = cres.data.classcode;
				$("#user-name",parent.document).attr("teachercode",teachercode).attr("classcode",classcode);
				var data = {
						cmd:"getAllClasses",
						model:"teacher",
						userKey:userKey,
						data:{
							teachercode:teachercode
						},
						remark:""
				};
				AjaxCrud.get2(serverUrl.ServerLoginUrl,data,function(res){
					if(res.result == 1 && res.data != undefined && res.data != ""){
						var contents = "";
						var list = res.data;
						for(var i = 0; i < list.length; i++){
							if(i == 0){
								contents += "<div class='classes-choice classes-choice-select' classcode='"+list[i].classcode+"'>"+list[i].name+"</div>";
							}else{
								contents += "<div class='classes-choice' classcode='"+list[i].classcode+"'>"+list[i].name+"</div>";
							}
						}
						$(".dialog-classes-contents").empty();
						$(".dialog-classes-contents").append(contents);
						changePage(PageUrl.tpositionUrl);
						$(".classes-choice").unbind("click");
						$(".classes-choice").click(function(){
							$(".classes-choice").removeClass("classes-choice-select");
							$(this).addClass("classes-choice-select");
						});
					}else{
						$(".dialog-classes-contents").empty();
						$(".dialog-classes-contents").append("<div class='classes-choice classes-choice-select'>没有相关信息</div>");
						changePage(PageUrl.tpositionUrl);
					}
				},null,null);
			}
		},null,null);
	}
	function pageBtns(){
		$(".left-menu-ul li").click(function(){
			var title = $(this).attr("title");
			$(".left-menu-ul li").removeClass("left-menu-liselect");
			$(this).addClass("left-menu-liselect");
			if(title == "定位"){
				changePage(PageUrl.tpositionUrl);
			}else if(title == "报警信息"){
				changePage(PageUrl.tsosUrl);
			}
		});
		$(".teacher-choice-classdia").show();
		$(".dialog-display-btnshow").click(function(){
			$(".dialog-display-btnshow").hide();
			$(".dialog-display-btnhide").show();
			$(".teacher-choice-classdia").animate({right:"0px"});
		});
		$(".dialog-display-btnhide").click(function(){
			$(".dialog-display-btnshow").show();
			$(".dialog-display-btnhide").hide();
			$(".teacher-choice-classdia").animate({right:"-110px"});
		});
	}
	function changePage(pageUrl){
		$("#aposition-body").attr("src",pageUrl);
	}
	function initPages(){
		var bodyRW = $(".index-body",parent.document).width() - $(".quality-left-page-menu").width()-2;
		$("#aposition-body").width(bodyRW);
	}
	
})();